home *** CD-ROM | disk | FTP | other *** search
/ QRZ! Ham Radio 4 / QRZ Ham Radio Callsign Database - Volume 4.iso / files / dsp / 56ktools / a5611.tz / a5611 / examples / reverb.a56 < prev    next >
Text File  |  1992-08-11  |  8KB  |  310 lines

  1. ;***************************************************************
  2. ; A stereo reverb for the DSP56001 signal processor.
  3. ; Developed by Quinn Jensen (jensenq@npd.novell.com) using
  4. ; Dr. Vercoe and company's csound code as a reference for the 
  5. ; configuration and gain values.
  6. ; This program fragment implements a stereo reberb effect
  7. ; on a DSP56001 processor.  The "depth" and wet/dry mix are
  8. ; adjustable.  The following filter configuration is employed:
  9. ;
  10. ;
  11. ;  Left in ------+------- "dry" gain -----------> sum -----> Left out
  12. ;                |                                 ^
  13. ;                v                                 |
  14. ;               sum --> reverb --> "wet" gain -----+
  15. ;                ^                                 |
  16. ;                |                                 v -
  17. ;  Right in -----+------- "dry" gain -----------> sum -----> Right out
  18. ;
  19. ;
  20. ; Note that the reverb path output is negated before summing with the
  21. ; right input signal.  This throws in 180 degrees of phase shift
  22. ; making for interesting results even with mono inputs 
  23. ; (i.e. Left in == Right in).
  24. ; The reverb element looks like this:
  25. ;
  26. ;
  27. ; Input ----+-----> comb1 ------+
  28. ;           |                   |
  29. ;           +-----> comb2 ---\  v
  30. ;           |                  sum -----> allpass1 --> allpass2 ---> output
  31. ;           +-----> comb3 ---/  ^
  32. ;           |                   |
  33. ;           +-----> comb4 ------+
  34. ;
  35. ; Each comb stage looks like this:
  36. ;
  37. ;                        +---- gain <-----+
  38. ;                        |                |
  39. ;                        v                |
  40. ; Input ---> gain ----> sum ---> delay ---+--> out
  41. ;
  42. ;
  43. ; The allpass stages look like:
  44. ;
  45. ;                         +--------- gain <---------+
  46. ;                         |                         |
  47. ;                         v                         |
  48. ; Input ---> gain --+--> sum ---> delay ---> sum ---+----> out
  49. ;                   |                         ^
  50. ;                   |                         |
  51. ;                   +--------> gain ----------+
  52. ;
  53. ; or,
  54. ;
  55. ;                             +-------> gain ----+
  56. ;                             |                  |
  57. ;                             |                  v
  58. ; Input ---> gain ----> sum --+--> delay --+--> sum -----> out
  59. ;                        ^                 |
  60. ;                        |                 |
  61. ;                        +----- gain <-----+
  62. ;
  63. ;
  64. ; I've seen both configurations in the literature, so I plotted the
  65. ; Z-transform and they are equivalent in the steady state.  They are indeed
  66. ; all-pass in the steady state but are supposed to have a subtle, discernable
  67. ; effect in "transient" audio signals.
  68. ;
  69. ; I think it could really use a couple more comb stages to fill in some of the 
  70. ; graininess.  The best possible "diffusion" is desired.  By the way, 
  71. ; I'd enjoy seeing any optimizations to the code.
  72. ;
  73. ; Quinn Jensen (jensenq@npd.novell.com or jensenq@qcj.icon.com)
  74. ;
  75.  
  76. include 'tdsg.basic.a56'    ;hardware specific initialization code
  77.  
  78. ;***************************************************************
  79. ;
  80. ;    Data and constants
  81. ;
  82. ;***************************************************************
  83.  
  84. dot                ;remember where we were in P-space
  85.     org    x:$10        ;put runtime variables in on-chip X-space
  86.  
  87. ; A spreadsheet was used to calculate the following numbers
  88. ;
  89. ; The gain of each feedback stage is given by
  90. ;
  91. ;    feedback gain = exp(delay * ln(.001)/duration)
  92. ;
  93. ; where "delay" is the delay of the comb or allpass stage in seconds,
  94. ; and "duration" is the time in seconds for the reverberated sound
  95. ; to decay to 1/1000 of its original amplitude.
  96. ;
  97.  
  98. ;  Reverb filter lengths and coefficients  
  99. ;  Sun Aug  4 16:36:16 1991    
  100. ;  
  101. ;      Sample rate               32.5520830 kHz      
  102. ;      Reverb duration            4.0000000 s        
  103. ;  
  104. ;  stage    delay(ms)    length        gain    actual
  105. ;  -----------------------------------------------------       
  106. ;  Comb1   29.7000000       967   0.9500031     29.71
  107. ;  Comb2   37.1000000      1208   0.9379399     37.11
  108. ;  Comb3   41.1000000      1338   0.9314831     41.10
  109. ;  Comb4   43.7000000      1423   0.9273101     43.71
  110. ;  All-1    5.0000000       163   0.9914025      5.01
  111. ;  All-2    1.7000000        55   0.9970685      1.69
  112.  
  113. in_atten equ                      0.3409091
  114. comb_atten equ                    0.0416667
  115. dry_init equ                      0.4000000    ; initial "dry" gain
  116. reverb_init equ                0.9900000    ; initial "wet" gain
  117.  
  118. ; comb 1 data and parameters
  119.  
  120. c1d equ                   $4000
  121. c1r  dc                     c1d
  122. c1m equ                     966
  123. c1c equ                           0.9500031
  124.  
  125. ; comb 2 data and parameters
  126.  
  127. c2d equ          c1d+      2048
  128. c2r  dc                     c2d
  129. c2m equ                    1207
  130. c2c equ                           0.9379399
  131.  
  132. ; comb 3 data and parameters
  133.  
  134. c3d equ          c2d+      2048
  135. c3r  dc                     c3d
  136. c3m equ                    1337
  137. c3c equ                           0.9314831
  138.  
  139. ; comb 4 data and parameters
  140.  
  141. c4d equ          c3d+      2048
  142. c4r  dc                     c4d
  143. c4m equ                    1422
  144. c4c equ                           0.9273101
  145.  
  146. ; allpass 1 data and parameters
  147.  
  148. a1d equ          c4d+      2048
  149. a1r  dc                     a1d
  150. a1m equ                     162
  151. a1c equ                           0.9914025
  152.  
  153. ; allpass 2 data and parameters
  154.  
  155. a2d equ          a1d+      2048
  156. a2r  dc                     a2d
  157. a2m equ                      54
  158. a2c equ                           0.9970685
  159.  
  160.     org    y:$0
  161.  
  162. reverb_on equ    reverb_init
  163. reverb_off equ    0
  164.  
  165. reverb_gain
  166.     dc    reverb_on
  167. dry_gain
  168.     dc    dry_init
  169.  
  170.     org    p:dot        ;go back to P-space
  171.  
  172. ;*****************************************************
  173. ;
  174. ; reverb initialization code
  175. ;
  176. ;*****************************************************
  177.  
  178. hf_init
  179.     rts
  180.  
  181. ;*****************************************************
  182. ;
  183. ; run-time controls
  184. ;
  185. ;*****************************************************
  186.  
  187. eff1_on        ;enable reverb
  188.     move            #reverb_on,y0
  189.     move            y0,y:<reverb_gain
  190.     rts
  191.  
  192. eff1_off    ;bypass reverb
  193.     move            #reverb_off,y0
  194.     move            y0,y:<reverb_gain
  195.     rts
  196.  
  197. ;*****************************************************
  198. ;
  199. ; interrupt time calculations
  200. ;
  201. ;*****************************************************
  202.  
  203. ;
  204. ; fs = 32.552083 kHz
  205. ;
  206.  
  207. hf_comp
  208.     jsr    <saveregs
  209. ;
  210. ;    L/R mix
  211. ;
  212.     clr    a    #in_atten,x1        ;clr a, get scale for mix
  213.     move        x:<in_l,x0        ;get left in
  214.     move        x0,x:<in_ls        ;save
  215.     macr    x0,x1,a x:<in_r,x0        ;a = scale * left, get right
  216.     macr    x0,x1,a    x0,x:<in_rs        ;a += scale * right, save right
  217.     clr    b        a,y0        ;y0 goes to the combs, b is sum
  218. ;
  219. ;    comb 1 
  220. ;
  221.     move        x:<c1r,r0
  222.     movec        #c1m,m0
  223.     move            y0,a
  224.     move        x:(r0),x1
  225.     add    x1,b    #c1c,x0
  226.     macr    x0,x1,a
  227.     move        a,x:(r0)+
  228.     move        r0,x:<c1r
  229. ;
  230. ;    comb 2
  231. ;
  232.     move        x:<c2r,r0
  233.     movec        #c2m,m0
  234.     move            y0,a
  235.     move        x:(r0),x1
  236.     add    x1,b    #c2c,x0
  237.     macr    x0,x1,a
  238.     move        a,x:(r0)+
  239.     move        r0,x:<c2r
  240. ;
  241. ;    comb 3
  242. ;
  243.     move        x:<c3r,r0
  244.     movec        #c3m,m0
  245.     move            y0,a
  246.     move        x:(r0),x1
  247.     add    x1,b    #c3c,x0
  248.     macr    x0,x1,a
  249.     move        a,x:(r0)+
  250.     move        r0,x:<c3r
  251. ;
  252. ;    comb 4
  253. ;
  254.     move        x:<c4r,r0
  255.     movec        #c4m,m0
  256.     move            y0,a
  257.     move        x:(r0),x1
  258.     add    x1,b    #c4c,x0
  259.     macr    x0,x1,a
  260.     move        a,x:(r0)+
  261.     move        r0,x:<c4r
  262. ;
  263. ;    scale
  264. ;
  265.     move        #comb_atten,x0    b,y0
  266.     mpyr    x0,y0,b
  267.  
  268. ;
  269. ;    allpass 1
  270. ;
  271.     move        x:<a1r,r0
  272.     movec        #a1m,m0
  273.     move        #a1c,x0
  274.     move        x:(r0),x1
  275.     macr    x0,x1,b    x1,a
  276.     move            b,y0
  277.     macr    -x0,y0,a b,x:(r0)+
  278.     move        r0,x:<a1r
  279. ;
  280. ;    allpass 2
  281. ;
  282.     move        x:<a2r,r0
  283.     movec        #a2m,m0
  284.     move        #a2c,x0
  285.     move        x:(r0),x1
  286.     macr    x0,x1,a    x1,b
  287.     move            a,y0
  288.     macr    -x0,y0,b a,x:(r0)+
  289.     move        r0,x:<a2r
  290. ;
  291. ;    output mix
  292. ;
  293.     move        b,x0
  294.     move            y:<reverb_gain,y0
  295.     mpyr    x0,y0,b        y:<dry_gain,y0
  296.     move        x:<in_ls,x0
  297.     move        b,a
  298.     macr    x0,y0,a    x:<in_rs,x0
  299.     macr    x0,y0,b    a,x:<out_l
  300.     move        b,x:<out_r
  301.  
  302.     jsr    <restregs
  303.     rts
  304.  
  305.     end
  306.  
  307.